package com.s64.ssm.controller;

import com.s64.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public String list(Model model) {
        model.addAttribute("userList", userService.getAll());
        return "user/list";
    }

    @GetMapping("/del/{id}")
    public String del(@PathVariable Integer id) {
        userService.del(id);
        return "redirect:/users";
    }
}
